
# generate figure 6

# load packages
library(rio) # load data
library(tidyverse) # data manipulation
library(sjPlot) # generate plots with predicted probabilities
library(scales) # better breaks for plots

# set working directory
setwd("~/replication_files/")

# load data for analysis
data_with_dictionary <- import("data/full_data.csv") %>%
  mutate(across(c(imf_program,field_discovery,grad_school_econ_usa,iso3c,year), as.factor)) # treat factors as factors

# estimate a model similar to that of table 2, but averaged across all countries and years
ols1_plot <- lm(policy_passage ~ resource_mentions_absolute + 
                  previous_policy +  grad_school_econ_usa + fdi_performance_index_lag +
                  imf_program + price_crudeoil_lag + price_crudeoil_difference + 
                  resource_rents_lag + log_gdp_per_capita_lag + gdp_growth_lag + field_discovery_lag + 
                  polyarchy + left_executive + protest, data = data_with_dictionary)

plot_model(ols1_plot, type = "pred", terms = c("resource_mentions_absolute[all]"), colors = "gs",
           se = vcovHC(ols1_plot, type = 'HC0', cluster = c('iso3c', 'Summary'))) +
  theme_classic() + labs(x = "Natural Resource Term Frequency", y = "Predicted Probability of Policy Passage", title = " ") + 
  scale_y_continuous(labels = label_percent(scale = 100, accuracy = 1))

ggsave(filename = "figures/fig6.pdf", width = 7, height = 5)
